﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;

namespace RooHui.Infrastructure.Entities.Repository
{
    [Table("P_AgentProfitStream")]
    public class P_AgentProfitStream : IEntity<P_AgentProfitStream>
    {
        [Key]
        [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }
        [Column(TypeName = "varchar")]
        [StringLength(128)]
        public string UserName { get; set; }
        public int Type { get; set; }
        [Column(TypeName = "varchar")]
        [StringLength(128)]
        public string Invester { get; set; }
        public int InvestmentId { get; set; }
        public int SettlementType { get; set; }
        public decimal Settlement { get; set; }
        public decimal Profit { get; set; }
        public DateTime RecordDate { get; set; }

        public override P_AgentProfitStream Find(string key)
        {
            int id = Int32.Parse(key);
            return Find(c => c.Id == id);
        }

        public override P_AgentProfitStream Find(System.Linq.Expressions.Expression<Func<P_AgentProfitStream, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.AgentProfitStream.FirstOrDefault(where);
                if (item != null)
                {
                    this.Id = item.Id;
                    this.Invester = item.Invester;
                    this.InvestmentId = item.InvestmentId;
                    this.SettlementType = item.SettlementType;
                    this.Settlement = item.Settlement;
                    this.Profit = item.Profit;
                    this.RecordDate = item.RecordDate;
                    this.Type = item.Type;
                    this.UserName = item.UserName;
                    return this;
                }
                return null;
            }
        }

        public override bool Any(System.Linq.Expressions.Expression<Func<P_AgentProfitStream, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.AgentProfitStream.Any(where);
            }
        }
    }
}
